#!/usr/bin/python3.7
# -*- coding: utf-8 -*-
# @Time    : 2021/3/5 4:30 下午
# @Author  : 白辉东
# @Email   : xyxk-huidong.bai@ximalaya.com
# @File    : excelUtils.py
# @Software: PyCharm

import pandas as pd


def read_module(excel_path, sheet_name):
    """
    获取excel表单个sheet数据
    :param excel_path: 表路径
    :param sheet_name: sheet页名称
    :return: query_list
    """
    data = pd.read_excel(excel_path, index_col=False, sheet_name=sheet_name, keep_default_na=False)
    query_list = []
    for i in range(0, len(data)):
        qid, domain, intent, query_text, asert_domain, asert_intent, tts, tts_start_tag, play_url_tag, speaker_action = data.values[i]
        query_dir = {'module': sheet_name,
                     'qid': qid,
                     'title': intent,
                     'query': query_text,
                     'asert_domain': asert_domain,
                     'asert_intent': asert_intent,
                     'tts': tts,
                     'tts_start_tag': tts_start_tag,
                     'play_url_tag': play_url_tag,
                     'speaker_action': speaker_action}

        query_list.append(query_dir)
    return query_list


def read_all_module(excel_path):
    """
    获取excel表所有数据
    :param excel_path: 表路径
    :return: all_list
    """
    df = pd.read_excel(excel_path, sheet_name=None)
    sheets = list(df)
    all_list = []
    for sheet in sheets:
        sheet_list = read_module(excel_path, sheet)
        all_list += sheet_list
    return all_list


if __name__ == '__main__':
    from config import projectPath
    print(read_module(projectPath.EXCEL_DIR, 'directives'))
